package com.geekchique.runningbuddy.view;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.geekchique.runningbuddy.activity.stopwatch.StopwatchTools;
import com.geekchique.runningbuddy.controller.IDayController;
import com.geekchique.runningbuddy.model.Jog;
import com.geekchique.runningbuddy.model.ListOfJogs;

public class JogListAdapter extends BaseAdapter{

	private ListOfJogs jogEntries;
	private final Activity activity;
	private IDayController dayOfJogDetailsController;


	public JogListAdapter(Activity activity, ListOfJogs jogEntries, IDayController dayOfJogDetailsController) {
		this.activity = activity;
		this.jogEntries = jogEntries;
		this.dayOfJogDetailsController = dayOfJogDetailsController;
	}

	public int getCount() {
		return this.jogEntries.size();
	}

	public Jog getItem(int position) {
		return this.jogEntries.get( position);
	}

	public long getItemId(int position) {
		return this.jogEntries.get(position)._id;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

	    TextView miles;
	    TextView jogname;
	    TextView timerun;

        miles = new TextView(activity);
        miles.setText("00");

        jogname = new TextView(activity);
        jogname.setText(jogEntries.get(position).name);

        timerun = new TextView(activity);
        timerun.setText(StopwatchTools.getFormattedDiff(jogEntries.get(position).getStartTime(), jogEntries.get(position).getStopTime()));

        JogEntryView todayView = new JogEntryView(activity, miles, jogname, timerun, jogEntries.get(position).startTime, dayOfJogDetailsController);
		return todayView;
	}

}
